//#include "http.h"

//HTTP::HTTP()
//{

//}
//bool HTTP::chkUser(QString pid, const QString pwd, int isFingerprintAuth, int& privilege, QString& resultMess)
//{
//    QNetworkAccessManager manager;
//    QUrl url(QStringLiteral("%1index.php?r=wsinterface/getcheckuser").arg("http://192.168.100.78/"));
//    //emit GlobalSignals::instance().Print(url.toString());
//    QNetworkRequest request(url);
//    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

//    QByteArray postData;
//    postData.append("police_num=").append(pid).append("&");
//    postData.append("password=").append(pwd).append("&");
//    postData.append("is_fingerprint_auth=").append(QString::number(isFingerprintAuth));
//    //创建QNetworkAccessManager对象manager，并使用post方法发送POST请求，并等待请求结束。
//    QNetworkReply* reply = manager.post(request, postData);
//    QTimer timer;
//    timer.setSingleShot(true); // Timer will fire only once
//    timer.setInterval(2000); // Set the timeout interval to 3 seconds (3000 milliseconds)

//    // Connect the timeout signal to a slot that will handle the timeout
//    QObject::connect(&timer, &QTimer::timeout, [&]() {
//        //emit GlobalSignals::instance().Print("Request timed out.1");
//        reply->abort(); // Abort the request if it's taking too long
//        return 0;
//    });

//    // Start the timer
//    timer.start();
//    while(!reply->isFinished())
//    {
//        qApp->processEvents();
//    }
//    //获取响应数据并进行解析。
//    QByteArray data = reply->readAll();
//    reply->deleteLater();

//    QString RespJson = QString::fromUtf8(data);

//    // 将JSON字符串转换为QJsonDocument对象
//    QJsonDocument jsonDocument = QJsonDocument::fromJson(RespJson.toUtf8());

//    // 检查JSON是否有效
//    if (jsonDocument.isNull()) {

//        return 0;
//    }
//    // 将QJsonDocument转换为QJsonObject
//    QJsonObject jsonObject = jsonDocument.object();

//           int result = jsonObject["result"].toInt();
//           QString msg = jsonObject["msg"].toString();

//           qDebug() << "Result:" << result;
//           qDebug() << "Message:" << msg;
//           if(result == 0)
//           {

//               return false;
//           }
//           if(result == 1 || result ==2)
//           {
//               return true;
//           }


//    return false;
//}

////int CHttpClient::uploadLogCustom( QString fileName,  QString devID,  QString PID,  QString trainsID,  QString trainsGroup)
////{
////    QUrl url(QStringLiteral("%1index.php?r=wsinterface/PutUploadLog").arg(URL));
////    emit GlobalSignals::instance().Print(url.toString());
////    QString postData = "police_num=" + PID + "&dev_id=" + devID + "&file_name=" + fileName + "&trains_id=" + trainsID + "&train_group_id=" + trainsGroup;

////    QNetworkAccessManager manager;
////    QNetworkRequest request(url);
////    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

////    QNetworkReply* reply = manager.post(request, postData.toUtf8());
////    QTimer timer;
////    timer.setSingleShot(true); // Timer will fire only once
////    timer.setInterval(2000); // Set the timeout interval to 3 seconds (3000 milliseconds)

////    // Connect the timeout signal to a slot that will handle the timeout
////    QObject::connect(&timer, &QTimer::timeout, [&]() {
////        emit GlobalSignals::instance().Print("Request timed out.");
////        reply->abort(); // Abort the request if it's taking too long
////        return 0;
////    });

////    // Start the timer
////    timer.start();
////    QEventLoop loop;
////    QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
////    loop.exec();

////    QByteArray data = reply->readAll();
////    reply->deleteLater();

////    QString RespJson = QString::fromUtf8(data);
////    emit GlobalSignals::instance().Print(RespJson);

////    if (RespJson == "1") // 上传成功
////        return 1;
////    else if (RespJson == "0") // 上传失败
////        return 0;
////    else if (RespJson == "-1") // 上传失败
////        return -1;
////    else
////        return -2;
////}

////int CHttpClient::uploadLogCustom(QString fileName, QString devID, QString PID)
////{

////    QNetworkAccessManager manager;
////    QUrl url(QStringLiteral("%1index.php?r=wsinterface/PutUploadLog").arg(URL));
////    emit GlobalSignals::instance().Print(url.toString());
////    QNetworkRequest request(url);
////    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

////    QByteArray postData;
////    postData.append("police_num=").append(PID).append("&");
////    postData.append("dev_id=").append(devID).append("&");
////    postData.append("file_name=").append(fileName);
////    //创建QNetworkAccessManager对象manager，并使用post方法发送POST请求，并等待请求结束。
////    QNetworkReply* reply = manager.post(request, postData);
////    QTimer timer;
////    timer.setSingleShot(true); // Timer will fire only once
////    timer.setInterval(2000); // Set the timeout interval to 3 seconds (3000 milliseconds)

////    // Connect the timeout signal to a slot that will handle the timeout
////    QObject::connect(&timer, &QTimer::timeout, [&]() {
////        emit GlobalSignals::instance().Print("Request timed out.");
////        reply->abort(); // Abort the request if it's taking too long
////        return 0;
////    });

////    // Start the timer
////    timer.start();
////    while(!reply->isFinished())
////    {
////        qApp->processEvents();
////    }
////    //获取响应数据并进行解析。
////    QByteArray data = reply->readAll();
////    reply->deleteLater();

////    QString RespJson = QString::fromUtf8(data);
////    emit GlobalSignals::instance().Print(RespJson);



////    if (RespJson == "1") // 上传成功
////        return 1;
////    else if (RespJson == "0") // 上传失败
////        return 0;
////    else if (RespJson == "-1") // 上传失败
////        return -1;
////    else
////        return -2;
////}
////int CHttpClient::GetUserByPoliceNum(QString pid, const QString pwd)
////{
////    QNetworkAccessManager manager;
////    QUrl url(QStringLiteral("%1index.php?r=wsinterface/GetUserByPoliceNum").arg(URL));
////    emit GlobalSignals::instance().Print(url.toString());
////    QNetworkRequest request(url);
////    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

////    QByteArray postData;
////    postData.append("police_num=").append(pid).append("&");
////    postData.append("password=").append(pwd).append("&");
////    //创建QNetworkAccessManager对象manager，并使用post方法发送POST请求，并等待请求结束。
////    QNetworkReply* reply = manager.post(request, postData);
////    QTimer timer;
////    timer.setSingleShot(true); // Timer will fire only once
////    timer.setInterval(2000); // Set the timeout interval to 3 seconds (3000 milliseconds)

////    // Connect the timeout signal to a slot that will handle the timeout
////    QObject::connect(&timer, &QTimer::timeout, [&]() {
////        emit GlobalSignals::instance().Print("Request timed out.");
////        reply->abort(); // Abort the request if it's taking too long
////        return 0;
////    });

////    // Start the timer
////    timer.start();
////    while(!reply->isFinished())
////    {
////        qApp->processEvents();
////    }
////    //获取响应数据并进行解析。
////    QByteArray data = reply->readAll();
////    reply->deleteLater();

////    QString RespJson = QString::fromUtf8(data);
////    emit GlobalSignals::instance().Print(RespJson);
////    // 将JSON字符串转换为QJsonDocument对象
////    QJsonDocument jsonDocument = QJsonDocument::fromJson(RespJson.toUtf8());

////    // 检查JSON是否有效
////    if (jsonDocument.isNull()) {
////        emit GlobalSignals::instance().Print("GetUserByPoliceNum Failed to parse JSON.");

////        return 0;
////    }

////    // 将QJsonDocument转换为QJsonObject
////    QJsonObject jsonObject = jsonDocument.object();

////    // 从QJsonObject中获取特定字段的值
////    int id = jsonObject["id"].toInt();
////    QString policeNum = jsonObject["police_num"].toString();
////    QString name = jsonObject["name"].toString();
////    QString roleId = jsonObject["role_id"].toString();
////    QString number = jsonObject["Number"].toString();
////    QString loginFailTimes = jsonObject["loginfail_times"].toString();
////    QString loginFailLockTime = jsonObject["loginfail_lock_time"].toString();
////    QString unitName = jsonObject["unit_name"].toString();

////    if(id==0)
////    {
////        return 0;
////    }
////    // 输出解析后的字段值
////    qDebug() << "id:" << id;
////    qDebug() << "police_num:" << policeNum;
////    qDebug() << "name:" << name;
////    qDebug() << "role_id:" << roleId;
////    qDebug() << "Number:" << number;
////    qDebug() << "loginfail_times:" << loginFailTimes;
////    qDebug() << "loginfail_lock_time:" << loginFailLockTime;
////    qDebug() << "unit_name:" << unitName;
////    return 1;

////}
////int CHttpClient::GetNotice(QString &title)
////{
////    QNetworkAccessManager manager;
////    QUrl url( QStringLiteral("%1index.php?r=wsinterface/Notice").arg(URL));
////    emit GlobalSignals::instance().Print(url.toString());
////    QNetworkRequest request(url);
////    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

////    QByteArray postData;
////    postData.append("");
////    //创建QNetworkAccessManager对象manager，并使用post方法发送POST请求，并等待请求结束。
////    QNetworkReply* reply = manager.post(request, postData);
////    QTimer timer;
////    timer.setSingleShot(true); // Timer will fire only once
////    timer.setInterval(2000); // Set the timeout interval to 3 seconds (3000 milliseconds)

////    // Connect the timeout signal to a slot that will handle the timeout
////    QObject::connect(&timer, &QTimer::timeout, [&]() {
////        emit GlobalSignals::instance().Print("Request timed out.");
////        reply->abort(); // Abort the request if it's taking too long
////        return 0;
////    });

////    // Start the timer
////    timer.start();
////    while(!reply->isFinished())
////    {
////        qApp->processEvents();
////    }

////    //获取响应数据并进行解析。
////    QByteArray data = reply->readAll();
////    reply->deleteLater();

////    QString RespJson = QString::fromUtf8(data);
////    emit GlobalSignals::instance().Print(RespJson);
////    if(RespJson=="[]")
////    {
////        title="";
////        return 1;
////    }
////    QJsonDocument jsonDocument = QJsonDocument::fromJson(RespJson.toUtf8());

////    if (!jsonDocument.isArray()) {
////        emit GlobalSignals::instance().Print("GetNotice Failed to parse JSON.");
////        return 0;
////    }

////    QJsonArray jsonArray = jsonDocument.array();

////    if (jsonArray.isEmpty()) {
////        emit GlobalSignals::instance().Print("GetNotice JSON array is empty.");
////        return 0;
////    }

////    QJsonObject jsonObject = jsonArray.at(0).toObject();

////    QString id = jsonObject.value("id").toString();
////    title = jsonObject.value("title").toString();
////    QString content = jsonObject.value("content").toString();
////    QString publisher = jsonObject.value("publisher").toString();
////    QString unitNumber = jsonObject.value("unit_number").toString();
////    QString publishTime = jsonObject.value("publish_time").toString();
////    QString deadline = jsonObject.value("deadline").toString();
////    QString type = jsonObject.value("type").toString();
////    QString status = jsonObject.value("status").toString();

////    qDebug() << "id:" << id;
////    qDebug() << "title:" << title;
////    qDebug() << "content:" << content;
////    qDebug() << "publisher:" << publisher;
////    qDebug() << "unit_number:" << unitNumber;
////    qDebug() << "publish_time:" << publishTime;
////    qDebug() << "deadline:" << deadline;
////    qDebug() << "type:" << type;
////    qDebug() << "status:" << status;
////    return 1;


////}

////int CHttpClient::GetZFYInfo(int index,QString str)
////{
////    QNetworkAccessManager manager;
////    QUrl url( QStringLiteral("%1index.php?r=wsinterface/getZFYInfo").arg(URL));
////    emit GlobalSignals::instance().Print(url.toString());
////    QNetworkRequest request(url);
////    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

////    QByteArray postData;
////    postData.append("zfyinfo=").append(str).append("&");
////    //创建QNetworkAccessManager对象manager，并使用post方法发送POST请求，并等待请求结束。
////    QNetworkReply* reply = manager.post(request, postData);
////    QTimer timer;
////    timer.setSingleShot(true); // Timer will fire only once
////    timer.setInterval(2000); // Set the timeout interval to 3 seconds (3000 milliseconds)

////    // Connect the timeout signal to a slot that will handle the timeout
////    QObject::connect(&timer, &QTimer::timeout, [&]() {
////        emit GlobalSignals::instance().Print("Request timed out.");
////        reply->abort(); // Abort the request if it's taking too long
////        return 0;
////    });

////    // Start the timer
////    timer.start();
////    while(!reply->isFinished())
////    {
////        qApp->processEvents();
////    }

////    //获取响应数据并进行解析。
////    QByteArray data = reply->readAll();
////    reply->deleteLater();

////    QString RespJson = QString::fromUtf8(data);
////    emit GlobalSignals::instance().Print(RespJson);
////    if(RespJson=="")
////    {
////        qDebug() << "请求失败";
////        return 0;

////    }
////    QStringList values = RespJson.split(',');

////    cSerial[index] = values.at(0).trimmed();         //执法记录仪产品序号
////    userNo[index] = values.at(1).trimmed();       //执法记录仪警员编号
////    userName[index] = values.at(2).trimmed(); //执法记录仪警员名称
////    unitNo[index] = values.at(3).trimmed();       //执法记录仪单位编号
////    unitName[index] = values.at(4).trimmed();  //执法记录仪单位名称
////    status[index] = values.at(5).trimmed();   //执法仪禁用状态
////    bindStatus[index] = values.at(6).trimmed();//执法仪配对状态；
////    watermark[index] = values.at(7).trimmed();//水印；
////    resolution[index] = values.at(8).trimmed();//分辨率；

////    //    QString id = jsonObject.value("id").toString();
////    //    title = jsonObject.value("title").toString();
////    //    QString content = jsonObject.value("content").toString();
////    //    QString publisher = jsonObject.value("publisher").toString();
////    //    QString unitNumber = jsonObject.value("unit_number").toString();
////    //    QString publishTime = jsonObject.value("publish_time").toString();
////    //    QString deadline = jsonObject.value("deadline").toString();
////    //    QString type = jsonObject.value("type").toString();
////    //    QString status = jsonObject.value("status").toString();

////    //    qDebug() << "id:" << id;
////    //    qDebug() << "title:" << title;
////    //    qDebug() << "content:" << content;
////    //    qDebug() << "publisher:" << publisher;
////    //    qDebug() << "unit_number:" << unitNumber;
////    //    qDebug() << "publish_time:" << publishTime;
////    //    qDebug() << "deadline:" << deadline;
////    //    qDebug() << "type:" << type;
////    //    qDebug() << "status:" << status;
////    return 1;


////}
